package com.example.yskjproject.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import com.example.yskjproject.R;
import com.example.yskjproject.model.WithDrawalRecordListModel;
import com.example.yskjproject.model.WithDrawalRecordModel;

import java.util.List;

public class WithDrawalRecordAdapter extends RecyclerView.Adapter<WithDrawalRecordAdapter.ViewHolder> {
    private List<WithDrawalRecordModel> mWithDrawalRecordList;

    public void addData(WithDrawalRecordListModel withDrawalRecordList) {
        mWithDrawalRecordList = withDrawalRecordList.getList();
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_withdrawal_record, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
//        holder.tvOrderNum.setText("订单编号:" + mWithDrawalRecordList.get(position).getList().get(position));
        holder.tvApplicationTime.setText(mWithDrawalRecordList.get(position).getCreated_at());
        holder.tvPaymentMethod.setText(mWithDrawalRecordList.get(position).getFinish_at());
        holder.withdrawalAmount.setText(mWithDrawalRecordList.get(position).getBalance() / 1000);
        holder.tvOrderState.setText(mWithDrawalRecordList.get(position).getStatus());
        holder.tvPaymentMethod.setText(mWithDrawalRecordList.get(position).getAccount());
    }

    @Override
    public int getItemCount() {
        return mWithDrawalRecordList.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        AppCompatTextView tvOrderState;
        AppCompatTextView tvApplicationTime;
        AppCompatTextView tvPaymentData;
        AppCompatTextView withdrawalAmount;
        AppCompatTextView tvPaymentMethod;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvOrderState = itemView.findViewById(R.id.tv_order_status);
            tvApplicationTime = itemView.findViewById(R.id.application_time);
            tvPaymentData = itemView.findViewById(R.id.payment_date);
            withdrawalAmount = itemView.findViewById(R.id.withdrawal_amount);
            tvPaymentMethod = itemView.findViewById(R.id.tv_payment_method);


        }
    }
}
